package hrm.action.cam;

import hrm.action.Action;
import hrm.action.ActionForward;
import hrm.dto.cam.CamDTO;
import hrm.dto.insa.EmployeeDTO;
import hrm.dto.org.OrgPersonDTO;
import hrm.serviceimple.CamServiceImple;
import hrm.serviceimple.EmployeeServiceImple;
import hrm.serviceimple.OrgServiceImple;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DecideCam implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		ActionForward actfoward = new ActionForward();
		CamServiceImple camService = CamServiceImple.getInstance();
		
		CamDTO dto = new CamDTO();
		String id = request.getParameter("id");
		String camseq = request.getParameter("camseq");
		String camstate = request.getParameter("camstate");
		String camstartdate = request.getParameter("camstartdate");
		String camenddate = request.getParameter("camenddate");
		String camcode = request.getParameter("camcode");
		String camorgcode = request.getParameter("camorgcode");
		String campositioncode = request.getParameter("campositioncode");
		String camclasscode = request.getParameter("camclasscode");
		String camdutycode = request.getParameter("camdutycode");
		String camorgofchief = request.getParameter("camorgofchief");
		String camnote = request.getParameter("camnote");
		
		dto.setId(id);
		dto.setCamseq(camseq);
		dto.setCamstate(camstate);
		dto.setCamstartdate(camstartdate);
		dto.setCamenddate(camenddate);
		dto.setCamcode(camcode);
		dto.setCamorgcode(camorgcode);
		dto.setCampositioncode(campositioncode);
		dto.setCamclasscode(camclasscode);
		dto.setCamdutycode(camdutycode);
		dto.setCamorgofchief(camorgofchief);
		dto.setCamnote(camnote);
		
		camService.updatePreCam(dto);
		
		EmployeeServiceImple employeeService = EmployeeServiceImple.getInstance();
		EmployeeDTO edto = new EmployeeDTO();
		edto.setId(id);
		edto.setOrgcode(camorgcode);
		edto.setPositioncode(campositioncode);
		edto.setDutycode(camdutycode);
		edto.setClasscode(camclasscode);
		employeeService.updateCamEmployee(edto);

		OrgServiceImple orgService = OrgServiceImple.getInstance();
		OrgPersonDTO odto = new OrgPersonDTO();
		odto.setOrgcode(camorgcode);
		odto.setId(id);
		odto.setOrgrelstartdate(camstartdate);
		odto.setOrgrelenddate(camenddate);
		odto.setOrgofchief(camorgofchief);
		orgService.endOrgperson(odto);
		orgService.insertOrgperson(odto);
	
		actfoward.setTiles(false);
		actfoward.setRedirect(true);
		actfoward.setUrl("camcontrol?command=precamcontrol&camstate&searchValue=2");
		return actfoward;
	}

}
